package com.jialiang.config;

import com.jialiang.common.constants.BaseEnum;

import java.util.Optional;

/**
 * 认证失败业务状态码
 *
 */
public enum AuthEnum implements BaseEnum<AuthEnum> {

    ERROR_NOT_FOUND(40400,"数据不存在"),
    ERROR_CONFLICT(40900,"数据冲突"),
    ERROR_INSERT(50000,"未知的插入数据失败"),
    ERROR_DELETE(50100,"未知的删除数据失败"),
    ERROR_UPDATE(50200,"未知的修改数据失败"),
    ERR_JWT_SIGNATURE(60100,"JWT验证签名失败，可能使用了伪造的JWT"),
    forceLoginOut(70000001,"您的账号在其他设备登录"),
    hasUserOnline(70000002,"当前已有用户在登录"),
    tokenInvalid(70000003,"登录已经过期，请重新登录"),
    tokenIllegal(70000004,"无效令牌"),
    methodNotSupport(70000005,"请求的方法不支持"),
    passwordIncorrect(70000006,"用户名或者密码错误"),
    accessDenied(70000007,"没有操作该功能的权限"),
    verifyCodeIncorrect(70000008,"验证码不正确"),
    accountNotExist(70000010,"账户不存在"),
    tokenExpired(70000009,"登录已经过期，请重新登录"),
    dataInvalid(70000010,"数据格式不正确"),
    requestFail(70000011,"请求失败"),
    AccountIsLock(70000012,"账号已经被禁用"),
    AuthFailure(70000013,"认证失败"),
    DeviceNotSupport(70000014,"设备未识别");

    /**
     * 枚举对象的值
     */
    private Integer code;

    private String message;

    AuthEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getName() {
        return message;
    }

    public static Optional<AuthEnum> of(Integer code) {
        return Optional.ofNullable(
                BaseEnum.parseByCode(AuthEnum.class, code));
    }
}
